package com.zh.hive;

import org.apache.hadoop.hive.ql.exec.UDF;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;

public class TestHiveUDF extends UDF {

	public Text evaluate(Text str) {
		return this.evaluate(str, new IntWritable(0));
	}

	public Text evaluate(Text str, IntWritable flag) {
		// 进行判断
		if (null != str) {
			if (flag.get() == 0) {
				return new Text(str.toString().toLowerCase());
			} else if (flag.get() == 1) {
				return new Text(str.toString().toUpperCase());
			} else {
				return null;
			}
		}
		return null;
	}
	
	public static void main(String[] args) {
		//大写转换为小写
		System.out.println(new TestHiveUDF().evaluate(new Text("HAOOPOP"))) ;
		System.out.println(new TestHiveUDF().evaluate(new Text("haddoop"),new IntWritable(1))) ;
	}
}
